package hammersmith.local.ui.gui;

import hammersmith.local.management.ShopManagement;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class RegisterMask extends JFrame {

	private static final long serialVersionUID = -1027817128032345716L;
	private JTextField txtCity;
	private JTextField txtPlz;
	private JTextField txtStreet;
	private JTextField txtFirstname;
	private JTextField txtName;
	private JTextField txtEmail;
	private JTextField txtPassword;

	public RegisterMask(final ShopManagement shop) {
		getContentPane().setLayout(null);
		this.setSize(494, 268);
		this.setLocationRelativeTo(null);
		this.setResizable(false);

		JLabel lblNeuerKunde = new JLabel("Neuer Kunde");
		lblNeuerKunde.setHorizontalAlignment(SwingConstants.CENTER);
		lblNeuerKunde.setFont(new Font("Dialog", Font.BOLD, 17));
		lblNeuerKunde.setBounds(6, 6, 482, 16);
		getContentPane().add(lblNeuerKunde);

		JLabel lblName = new JLabel("Name:");
		lblName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblName.setBounds(31, 45, 77, 16);
		getContentPane().add(lblName);

		JLabel lblVorname = new JLabel("Vorname:\n");
		lblVorname.setHorizontalAlignment(SwingConstants.RIGHT);
		lblVorname.setBounds(31, 85, 77, 16);
		getContentPane().add(lblVorname);

		JLabel lblStrae = new JLabel("Adresse:");
		lblStrae.setHorizontalAlignment(SwingConstants.RIGHT);
		lblStrae.setBounds(31, 124, 77, 16);
		getContentPane().add(lblStrae);

		JLabel lblPlz = new JLabel("PLZ:");
		lblPlz.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPlz.setBounds(31, 162, 77, 16);
		getContentPane().add(lblPlz);

		JLabel lblOrt = new JLabel("Ort:");
		lblOrt.setHorizontalAlignment(SwingConstants.RIGHT);
		lblOrt.setBounds(31, 201, 77, 16);
		getContentPane().add(lblOrt);

		JLabel lblEmail = new JLabel("E-Mail:");
		lblEmail.setHorizontalAlignment(SwingConstants.RIGHT);
		lblEmail.setBounds(260, 91, 61, 16);
		getContentPane().add(lblEmail);

		JLabel lblPasswort = new JLabel("Passwort:");
		lblPasswort.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPasswort.setBounds(260, 131, 61, 16);
		getContentPane().add(lblPasswort);

		txtCity = new JTextField();
		txtCity.setBounds(114, 195, 134, 28);
		getContentPane().add(txtCity);
		txtCity.setColumns(10);

		txtPlz = new JTextField();
		txtPlz.setColumns(10);
		txtPlz.setBounds(114, 156, 134, 28);
		getContentPane().add(txtPlz);

		txtStreet = new JTextField();
		txtStreet.setColumns(10);
		txtStreet.setBounds(114, 118, 134, 28);
		getContentPane().add(txtStreet);

		txtFirstname = new JTextField();
		txtFirstname.setColumns(10);
		txtFirstname.setBounds(114, 79, 134, 28);
		getContentPane().add(txtFirstname);

		txtName = new JTextField();
		txtName.setColumns(10);
		txtName.setBounds(114, 39, 134, 28);
		getContentPane().add(txtName);

		txtEmail = new JTextField();
		txtEmail.setColumns(10);
		txtEmail.setBounds(325, 85, 134, 28);
		getContentPane().add(txtEmail);

		txtPassword = new JTextField();
		txtPassword.setColumns(10);
		txtPassword.setBounds(325, 125, 134, 28);
		getContentPane().add(txtPassword);

		JButton btnOk = new JButton("Ok");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int id = shop.addNewCustomer(txtName.getText(),
						txtFirstname.getText(), txtStreet.getText(),
						txtPlz.getText(), txtCity.getText(),
						txtEmail.getText(), txtPassword.getText());

				JOptionPane.showMessageDialog(null,
						"Sie sind nun registriert! \n Ihre ID lautet: " + id);
				dispose();

			}
		});
		btnOk.setBounds(298, 195, 61, 29);
		getContentPane().add(btnOk);

		JButton btnAbbrechen = new JButton("Abbrechen");
		btnAbbrechen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnAbbrechen.setBounds(360, 195, 117, 29);
		getContentPane().add(btnAbbrechen);

		this.setVisible(true);

	}
}
